<?php

namespace App\Http\Controllers\Web;

use App\Models\Articles;
use App\Models\Members;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class IndexController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {	
		
        $data = Members::from('members as m')
        ->select('m.*','ml.name as levelName','ml.discount')
        ->leftJoin('member_level as ml','ml.id','=','m.level')
        ->where('m.id','=',auth('web')->user()->id)
        ->first();
        
        $news = Articles::where("is_display","=","0")->where("typeid","=",1);
		        
		$news->where(function ($query) {
            $query->where('read_power', '=', 0)
            ->orwhere('read_power', '=', 2);
        });      
		  
        $data["news"] = $news->orderBy("id","desc")->Limit(5)->get();
        
        return view('web.index.index',$data);
    }
}
